﻿using System;
using System.Windows.Forms;
using System.Runtime.InteropServices;
using System.Drawing;
using System.IO;

namespace DiPlaner
{
    static class Program
    {

        [STAThread]
        static void Main()
        {
            
            if (!File.Exists("wh.dll"))
            {
                MessageBox.Show("wh.dll is missing!", "WARNING", MessageBoxButtons.OK, MessageBoxIcon.Warning, MessageBoxDefaultButton.Button1, MessageBoxOptions.ServiceNotification);
                return;
            }

            Application.EnableVisualStyles();
            Application.SetCompatibleTextRenderingDefault(false);
            //Application.Run(new DiForm());
            (new MainForm()).ShowDialog();
        }
        /*

        #region Imports
        
        [DllImport("wh.dll")]
        private static extern void Hook();
        [DllImport("wh.dll")]
        private static extern void UnHook();
        [DllImport("wh.dll")]
        private static extern void SetVars(IntPtr handle, Size newSize);

        
        [StructLayout(LayoutKind.Sequential)]
        struct RECT
        {
            public int left, top, right, bottom;
        }
        [StructLayout(LayoutKind.Sequential)]
        struct WINDOWINFO
        {
            public uint cbSize;
            public RECT rcWindow;
            public RECT rcClient;
            public uint dwStyle;
            public uint dwExStyle;
            public uint dwWindowStatus;
            public uint cxWindowBorders;
            public uint cyWindowBorders;
            public ushort atomWindowType;
            public ushort wCreatorVersion;

            public WINDOWINFO(Boolean? filler)
                : this()   // Allows automatic initialization of "cbSize" with "new WINDOWINFO(null/true/false)".
            {
                cbSize = (UInt32)(Marshal.SizeOf(typeof(WINDOWINFO)));
            }

        }
        [return: MarshalAs(UnmanagedType.Bool)]
        [DllImport("user32.dll", SetLastError = true)]
        private static extern bool GetWindowInfo(IntPtr hwnd, ref WINDOWINFO pwi);

        [DllImport("user32.dll", SetLastError = false)]
        static extern IntPtr GetDesktopWindow();

        #endregion

        public static void _moveWindow(int index)
        {
            if (DiForm.Hooked) try
                {
                    var bot = DiForm.BotLines[index - 1].profile.Bot;
                    var handle = DiRunTime.FindProcess(bot.d3_path).MainWindowHandle;
                    var size = bot.size;
                    var position = bot.pos;

                    SetVars(handle, size);
                    DiRunTime.MoveWindow(handle, position.X, position.Y, size.Width, size.Height, true);
                }
                catch { }
        }

        public static void _restoreWindow(int index)
        {
            if (!DiForm.Hooked) return;
            var bot = DiForm.BotLines[index - 1].profile.Bot;
            var handle = DiRunTime.FindProcess(bot.d3_path).MainWindowHandle;

            var pwi = new WINDOWINFO();
            GetWindowInfo(GetDesktopWindow(), ref pwi);
            var size = new Size
                           {
                               Width = pwi.rcWindow.right,
                               Height = pwi.rcWindow.bottom
                           };

            var position = bot.pos;

            SetVars(handle, size);
            DiRunTime.MoveWindow(handle, position.X, position.Y, 808, 630, true);
        }

        public static void StartHook()
        {
            if (DiForm.Hooked) return;
            DiForm.Hooked = true;
            Hook();
        }

        public static void StopHook()
        {
            if (!DiForm.Hooked) return;
            DiForm.Hooked = false;
            UnHook();
        }//*/
    }
}
